package com.cat.dataStructure03;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/split-array-into-maximum-number-of-subarrays/
 * @create 2025/11/10 09:04
 * @since JDK17
 */

class Solution33 {
    public int minOperations(int[] nums) {
        int ans = 0, top = -1;
        for (int x : nums) {
            while (top >= 0 && nums[top] > x) {
                top--;
                ans++;
            }
            if (top < 0 || x != nums[top]) {
                nums[++top] = x;
            }
        }
        return ans + top + (nums[0] > 0 ? 1 : 0);
    }
}